package com.epic;

import org.hashids.Hashids;

import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;

/**
 * use tmp avro table transform to parquet table one day and setup partitions by sql
 * insert into '%repartitions(4)%' xxx_his.table select * from xxx_tmp.table where ns_date='xxxxx'
 * by Spark SQL
 * Hadoop3 EC tech and snappy
 * disk soft raid tech
 */
public class Main {
    public static String encodeStr(String data){
        String ret = "";
        byte[] bytes;
        try{
            bytes = data.getBytes(StandardCharsets.UTF_8);
            for (int i = 0; i < bytes.length; i++) {
                ret += Integer.toString((bytes[i] & 0xff) + 0x100,16).substring(1);
            }
            return  ret;

        }catch (Exception e){
            System.out.println();
        }
        return ret;
    }
    public static void main(String[] args) {
        final String SALT = "this is my salt";
        final int MIN_HASH_LENGTH = 11;

        Hashids hashids = new Hashids(SALT, MIN_HASH_LENGTH);
        String encryptString = hashids.encode(347L);
        String a2 = "我是中午10.65.133.71065.68";
        String encryptString2 = hashids.encodeHex(encodeStr(a2));
        /**
         * xolyn7R7NxuzBQ5qOrXV
         * Hashids是一款非常小巧跨语言的开源库，可以将数字或者16进制字符串转为短且唯一不连续的字符串，
         * Hashids是双向编码（支持encode和decode），比如，它可以将347之类的数字转换为yr8之类的字符串，
         * 也可以将yr8之类的字符串重新解码为347之类的数字。
         * 当某些资源对外提供时，我们希望能够有使用一种编码算法能够将具有递增性的标识码进行编码为无递增性的标识
         */

        System.out.println(encryptString2);

        System.out.println(encryptString);
    }

}
